/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *	  http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.milib.dbg.model.content {
	import com.googlecode.milib.base.MLBaseClass;
	import com.googlecode.milib.dbg.MLDBG;
	import com.googlecode.milib.dbg.model.content.MLDBGValuesListModel;

	import flash.utils.describeType;

	/**
	 * @author Marek Brun
	 */
	public class MLDBGClassVariablesListModel extends MLDBGValuesListModel {

		private var obj:Object;
		private var mldbg:MLDBG;

		public function MLDBGClassVariablesListModel(obj:Object) {
			super(false);
			this.obj=obj;
			mldbg=MLDBG.getInstance();
			refersh();
		}
		
		public function refersh():void {
			var typeXML:XML=describeType(obj);
			var i:uint;
			
			var values:Array=[];
			for(i=0;i<typeXML.variable.length();i++){
				values.push({name:typeXML.variable[i].@name, obj:typeXML.variable[i]});
			}
			values.sortOn('name', Array.CASEINSENSITIVE);
			
			for(i=0;i<values.length;i++){
				addValue(values[i].obj.@name, mldbg.getLink(obj[values[i].obj.@name]));
			}
			for(i=0;i<typeXML.accessor.length();i++){
				if(typeXML.accessor[i].@access.toString()=="writeonly"){ continue; }
				addValue(typeXML.accessor[i].@name, mldbg.getLink(obj[typeXML.accessor[i].@name]));
			}
			if(obj is MLBaseClass){
				addValue('<b><i>	private</i>:</b>');
				var mlbase:MLBaseClass=MLBaseClass(obj);
				var variables:Array=mlbase.getPrivateVariables();
				for(i=0;i<variables.length;i++){
					addValue(variables[i][0], dbg.link(variables[i][1]));
				}
			}
		}
	}
}
